package de.koller.worlders.engine.entity.mo.vehicle;

import de.koller.oceanFramework.tree.Mother;
import de.koller.worlders.WSea;
import de.koller.worlders.engine.WInputGL;
import org.lwjgl.input.Keyboard;

public class UfoSteer extends WSea {
	@Mother private Ufo ufo;

	@Override
	protected void init() {
		super.init();
		
		wroot.getEntityContainer().setShowCrosshair( false );
	}
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		if( ufo.isDeath() )
			return;
		
		if( wroot.getDebug().isActive() || wroot.getGui().getConsoleInput().isOpen() )
			return;
		
		wroot.getInput().setMouseGrab( true );
		
		throttle( elapsedTime );
		gear();
		reseting();
	}

	private void reseting() {
		WInputGL in = wroot.getInput();
		
		if( !in.isKeyPressed( Keyboard.KEY_R ) )
			return;
		
		ufo.reset();
	}
	
	private void gear() {
		WInputGL i = wroot.getInput();
		
		ufo.gear( i.getMouseDX() * 0.002f );
	}
	
	private void throttle( int et ) {
		WInputGL i = wroot.getInput();
		
		ufo.setThrottle( i.isKeyDown( Keyboard.KEY_W ) );
	}
	
}
